/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Util;

/**
 *
 * @author Jack
 */
import java.sql.*;
import Database.ConnectToDatabase;
import java.util.Vector;

public class Solution {

    private int idsolution;
    private String solution;
    private int idbackend;
    private int idreport;
    private java.sql.Date date_solve;

    /**
     * @return the idsolution
     */
    public int getIdsolution() {
        return idsolution;
    }

    /**
     * @param idsolution the idsolution to set
     */
    public void setIdsolution(int idsolution) {
        this.idsolution = idsolution;
    }

    /**
     * @return the solution
     */
    public String getSolution() {
        return solution;
    }

    /**
     * @param solution the solution to set
     */
    public void setSolution(String solution) {
        this.solution = solution;
    }

    /**
     * @return the idbackend
     */
    public int getIdbackend() {
        return idbackend;
    }

    /**
     * @param idbackend the idbackend to set
     */
    public void setIdbackend(int idbackend) {
        this.idbackend = idbackend;
    }

    /**
     * @return the idreport
     */
    public int getIdreport() {
        return idreport;
    }

    /**
     * @param idreport the idreport to set
     */
    public void setIdreport(int idreport) {
        this.idreport = idreport;
    }

    public static Solution ListIDSL(int idreport) {
        Solution listd = new Solution();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from solution where idreport=" + idreport;
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                Solution d = new Solution();
                d.setIdsolution(rs.getInt("idsolution"));
                d.setSolution(rs.getString("solution"));
                d.setIdreport(rs.getInt("idreport"));
                d.setIdbackend(rs.getInt("idbackend"));
                d.setDate_solve(rs.getDate("datesolve"));
                listd = d;
            }
        } catch (Exception e) {
            listd = null;
        }
        return listd;
    }

    public static String ListNameBackEnd(int idreport) {
        String liste = "";
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select nameemployee from employee,solution where solution.idbackend=employee.idemployee and solution.idreport=" + idreport;
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                liste = rs.getString("nameemployee");
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    /**
     * @return the date_solve
     */
    public java.sql.Date getDate_solve() {
        return date_solve;
    }

    /**
     * @param date_solve the date_solve to set
     */
    public void setDate_solve(java.sql.Date date_solve) {
        this.date_solve = date_solve;
    }

    public boolean addsolution() {
        return CommonQuery.Command("insert into solution values('" + this.solution + "'," + this.idbackend + ",'" + this.date_solve + "'," + this.idreport + ")");
    }

    public boolean updatesolution() {
        return CommonQuery.Command("update solution set solution='" + this.solution + "',idbackend=" + this.idbackend + ",datesolve='" + this.date_solve + "' where idreport=" + this.idreport);
    }

    public boolean deletesolution() {
        return CommonQuery.Command("delete solution where idreport=" + this.idreport);
    }
}
